﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssemblyInfoEditor.Project
{
    public class ProjectAssemblyInfoEnumerator : IEnumerator<ProjectAssemblyInfo>
    {
        protected ProjectAssemblyInfoCollection collection;
        protected ProjectAssemblyInfo currentItem;
        protected int currentItemIndex;

        /// <summary>
        /// Constructor.
        /// </summary>
        public ProjectAssemblyInfoEnumerator()
        {

        }

        public ProjectAssemblyInfoEnumerator(ProjectAssemblyInfoCollection enumerableCollection)
        {
            collection = enumerableCollection;
            currentItemIndex = -1;
            currentItem = default(ProjectAssemblyInfo);
        }

        public void Dispose()
        {
            collection = null;
            currentItem = default(ProjectAssemblyInfo);
            currentItemIndex = -1;
        }

        public virtual ProjectAssemblyInfo Current
        {
            get { return currentItem; }
        }

        object System.Collections.IEnumerator.Current
        {
            get { return currentItem; }
        }

        public virtual bool MoveNext()
        {
            // Increment the current index
            currentItemIndex++;

            // Ensure the index is not outside the bounds of the collection
            if (currentItemIndex < collection.Count)
            {
                // Index is within collection bounds. Set the item
                // at the new index as the value for our current item
                currentItem = collection[currentItemIndex];
            }
            else
            {
                // Index is outside the bounds of the collection. Kill it with fire!
                return false;
            }

            // If we got this far, all went well.
            return true;
        }

        public virtual void Reset()
        {
            currentItem = default(ProjectAssemblyInfo);
            currentItemIndex = -1;
        }
    }
}
